function resizeImage(ImgD,iwidth,iheight){ 
	 var image=new Image(); 
     image=ImgD;
     if(((image.width>image.height)?image.width:image.height)==iwidth)
    	 return;
     if(image.width>0 && image.height>0){ 
        if(image.width/image.height>= iwidth/iheight){ 
           if(image.width>iwidth){ 
               ImgD.width=iwidth; 
               ImgD.height=(image.height*iwidth)/image.width; 
           }else{ 
                  ImgD.width=image.width; 
                  ImgD.height=image.height; 
                } 
               ImgD.alt=image.width+"×"+image.height; 
        } 
        else{ 
                if(image.height>iheight){ 
                       ImgD.height=iheight; 
                       ImgD.width=(image.width*iheight)/image.height; 
                }else{ 
                        ImgD.width=image.width; 
                        ImgD.height=image.height; 
                     } 
                ImgD.alt=image.width+"×"+image.height; 
            }
	 }
}

divH=300;
divW=300;

function doResizeDiv(w,h)
{
		if(w>0 && h>0){ 
			if(w/h>= 1){ 
			   if(w>300){ 
				   divW=300; 
				   divH=(h*300)/w+15; 
			   }else{ 
					  divW=w; 
					  divH=h+15; 
					} 
			} 
			else{ 
					if(h>300){ 
						   divH=315; 
						   divW=(w*300)/h; 
					}else{ 
							divW=w; 
							divH=h+15; 
						 } 
				}
		 }	
	document.getElementById('preview').style.height=divH+"px";
	document.getElementById('preview').style.width=divW+"px";	
}

function setLargeDiv(divId,w,h)
{
     if(w>0 && h>0){ 
        if(w>500){
			divW=500;
			divH=h*500/w;
        } 
        else{ 
               divW=w;
			   divH=h;
            }
	 }
	 //alert(parseInt(divH)+20);	 
	 document.getElementById(divId).style.width=parseInt(divW)+5+"px";
	 document.getElementById(divId).style.height=parseInt(divH)+20+"px";
	 //alert(w+'x'+h);
	 //alert(divW+'x'+divH);
}

function setSmallDiv(divId,w,h)
{
     if(w>0 && h>0){ 
        if(w/h>= 1){ 
           if(w>300){ 
               divW=300; 
               divH=(h*300)/w; 
           }else{ 
                  divW=w; 
                  divH=h; 
                } 
        } 
        else{ 
                if(h>300){ 
                       divH=300; 
                       divW=(w*300)/h; 
                }else{ 
                        divW=w; 
                        divH=h; 
                     } 
            }
	 }
	 
	 document.getElementById(divId).style.width=parseInt(divW)+5+"px";
	 document.getElementById(divId).style.height=parseInt(divH)+5+"px";
}

function showLarge(str)
{
	divId="div"+str;
	imgId="img"+str;
	hidId="hid"+str;
	arr = document.getElementById(hidId).value.split(',');
	obj=document.getElementById(imgId);
	$('#'+divId).hide();
	$('#'+divId).html("<div style='font-size:12px;'><span onclick=\"showOriPic('"+arr[2]+"')\">" +
			"<a href='#'>查看原图</a></span></div> <img style='border:2px double #CCC;' id='"+imgId+"' src='"+arr[2]+"' onload='showLargeImg(this)' onclick=\"showSmall('"+str+"');\" />");
	
	setLargeDiv(divId,arr[0],arr[1]);
	$('#'+divId).show('slow');
}

function showSmall(str)
{
	divId="div"+str;
	imgId="img"+str;
	hidId="hid"+str;
	arr = document.getElementById(hidId).value.split(',');
	obj=document.getElementById(imgId);
	$('#'+divId).hide();
	$('#'+divId).html("<img  style='border:2px double #CCC;'  id='"+imgId+"' src='"+obj.src+"' onload='resizeImage(this,300,300)' onclick=\"showLarge('"+str+"');\" />");
	
	setSmallDiv(divId,arr[0],arr[1]);
	$('#'+divId).show('slow');	
}

function showLargeImg(ImgD){ 
	 var image=new Image(); 
     image=ImgD;
     if(image.width>0 && image.height>0){ 
        if(image.width>500){
			ImgD.width=500;
			ImgD.height=image.height*500/image.width;
        } 
        else{ 
               ImgD.width=image.width;
			   ImgD.height=image.height;
            }
	 }
}

function showOriPic(src)
{
	window.open(src);
}

function delPic()
{
	$('#preview').hide();
	$('#isPicUp').val("");	
}